package com.lovo.homework7_11DouDiZhu;

import java.util.*;

public class DouDiZhu {
    // 初始化54张扑克牌
    public static ArrayList<Card> list = new ArrayList();


    public void init() {
        //1.定义一个存放点数的数组
        String[] point = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //2.定义一个存放花色的数组
        String[] type = {"♥", "♦", "♣", "♠"};
        //定义一个存放大小的数组
        //String[] number = {"0","1","2","3","4","5","6","7","8","9","10","11","12"};
        //记录真实的牌的大小
        int index = 0;
        //3.组合点数与花色
        for (String points : point) {
            index++;
            for (String types : type) {
                Card card = new Card(points, types, index);
                list.add(card);
            }
        }
        Card cardBig = new Card("JOKER", "🤡", 15);
        Card cardLittle = new Card("joker", "🤡", 14);
        list.add(cardLittle);
        list.add(cardBig);
        System.out.println(list);
    }

    // 洗牌
    public void xipai() {
        Collections.shuffle(list);
        System.out.println(list);
    }

    // 发牌
    public void fapai() {
        ArrayList<Card> a = new ArrayList<>();
        ArrayList<Card> b = new ArrayList<>();
        ArrayList<Card> c = new ArrayList<>();
        for (int i = 0; i < (list.size() - 3); i++) {
            Card newCard = list.get(i);
            if (i % 3 == 0) {
                a.add(newCard);
            } else if (i % 3 == 1) {
                b.add(newCard);
            } else {
                c.add(newCard);
            }
        }
        System.out.print(a);
        System.out.println("");

        System.out.print(b);

        System.out.println("");

        System.out.print(c);

        System.out.println("");
    }
    // 排序

//    public void order(){
//        list.sort(new Comparator<Card>() {
//            @Override
//            public int compare(Card o1, Card o2) {
//                return o1.getNumber()-o2.getNumber();
//            }
//        });
//    }

    public static void main(String[] args) {
        DouDiZhu douDiZhu = new DouDiZhu();
        douDiZhu.init();
        douDiZhu.xipai();
        douDiZhu.fapai();
        //douDiZhu.order();
//        list.sort(new Comparator<Card>() {
//            @Override
//            public int compare(Card o1, Card o2) {
//                return o1.getNumber()-o2.getNumber();
//            }
//        });

    }
}
